/* GUI CONVERTED from rcabslmt.p (converter v1.76) Wed Sep  4 05:46:11 2002 */
/* rcabslmt.p - SHIPPER LINE CHARGES POP-UP/MAINTENANCE SCREENS         */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.17 $                                               */
/*                                                                      */
/* Revision: 1.15      BY: Dan Herman   DATE: 07/16/01   ECO: *P006*    */
/* Revision: 1.16      BY: Dan Herman   DATE: 08/15/01   ECO: *P01L*    */
/* $Revision: 1.17 $       BY: Dan Herman       DATE: 9/03/02 ECO: *P0HG*  */
/*V8:ConvertMode=Maintenance                                            */
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.           */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN        */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES.*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*-------------------------------------------------------------------------
  Purpose: This program allows the user to edit and add line charges to the
           shipper for an order/line/line item. The shipper line charges
           (absl_det) are displayed in a pop-up frame and are created from the
           sales order line charges (sodlc_det) for the order and line.
           One time only line charges on the sales order line that have already
           been charged are not added.

  Notes:
----------------------------------------------------------------------------*/

{mfdeclre.i}
{pxpgmmgr.i}
{pxphdef.i cclcxr}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

define input parameter ipSoRecNo as recid no-undo.
define input parameter ipSodRecNo as recid no-undo.
define input parameter ipAbsID like abs_id no-undo.
define input parameter ipShipFrom like abs_shipfrom no-undo.

define variable del-yn like mfc_logical no-undo.
define variable ctr as integer no-undo.
define variable new_absl_det like mfc_logical no-undo.
define variable l_is_first like mfc_logical no-undo.
define variable where_we_are as integer no-undo.
define variable absldet_recid as recid no-undo.
define variable new_line_nbr like absl_lc_line no-undo.
define variable default_lc_type like ccl_charge_type no-undo.
define variable default_edit_lc_shipper
                like ccl_edit_lc_shipper no-undo.
define variable addcharge like rsn_desc
                         column-label "Additional!Charges" no-undo.
define variable absl_updateable like mfc_logical no-undo.
define variable result-status as character no-undo.
define variable vSalesAccount as character no-undo.
define variable vSubAccount as character no-undo.
define variable vCostcenter as character no-undo.
define variable vTaxable as logical no-undo.
define variable vTaxClass as character no-undo.
define variable sodlc_recno as recid no-undo.
define variable op_price as decimal no-undo.
define variable line_price as decimal no-undo.
define variable vQty like abs_qty no-undo.

define  frame line_det.

/*V8:EditableDownFrame=line_det */
FORM /*GUI*/ 
   absl_lc_line
   addcharge view-as fill-in size 15 by 1
   absl_trl_code
   absl_lc_amt
   absl_charge_type
   absl_ref column-label "Ref" view-as fill-in size 15 by 1
with frame line_det down centered
scroll 1 width 80
title color normal (getFrameTitle("ADDITIONAL_LINE_CHARGES",29)) THREE-D /*GUI*/.


/* SET EXTERNAL LABELS */
setFrameLabels(frame line_det:handle).


FUNCTION code_desc returns character (input trlcode as character):
   define variable code_desc as character no-undo.
   for first trl_mstr
      fields (trl_code trl_desc)
      where
       trl_code = trlcode
       no-lock:
       code_desc = trl_desc.
   end.
   return code_desc.
END FUNCTION.


on leave of absl_trl_code do:
   run charge_label (input (input absl_trl_code),
                     output addcharge).
   display addcharge with frame line_det.

        
  do on error undo, leave:
      run q-leave in global-drop-down-utilities.
  end.
  run q-set-window-recid in global-drop-down-utilities.
  if return-value = "error" then return no-apply.   

end.


for first so_mstr
   fields (so_nbr so_sched so_ship)
   where recid(so_mstr) = ipSoRecNo no-lock:
end.

for first sod_det
   fields(sod_nbr sod_line sod_site sod_dock sod_ship)
   where recid(sod_det) = ipSodRecNo no-lock:
end.

/* SET SO_TAX_DATE TO A VALID*/
/* DATE IF A SCHEDULED ORDER*/
if so_sched then
   run set_tax_date in THIS-PROCEDURE
       (input so_nbr,
        input today).

for first abs_mstr
   fields(abs_id abs_shipfrom abs_ship_qty abs_qty)
   no-lock where
   abs_id = ipAbsID  and
   abs_shipfrom = ipShipFrom:
end.


for first ccl_ctrl
   fields(ccl_charge_type ccl_edit_lc_shipper)
   no-lock:
   assign
      default_lc_type = ccl_charge_type
      default_edit_lc_shipper = ccl_edit_lc_shipper.
end.

for first ccls_mstr
   fields(ccls_shipfrom ccls_shipto
          ccls_charge_type ccls_edit_lc_shipper)
   no-lock
   where
      ccls_shipfrom = sod_site
   and ccls_shipto = (if sod_dock <> "" then sod_dock
                      else if sod_ship <> "" then sod_ship
                      else so_ship):
   assign
      default_lc_type = ccls_charge_type
      default_edit_lc_shipper = ccls_edit_lc_shipper.
end.
if not available ccls_mstr then
   for first ccls_mstr
      fields(ccls_shipfrom ccls_shipto
             ccls_charge_type ccls_edit_lc_shipper)
      no-lock
      where
         ccls_shipfrom = ""
      and ccls_shipto = (if sod_dock <> "" then sod_dock
                         else if sod_ship <> "" then sod_ship
                         else so_ship):
      assign
         default_lc_type = ccls_charge_type
         default_edit_lc_shipper = ccls_edit_lc_shipper.
end.

sodlc_recno = ?.
if default_edit_lc_shipper then do:

   view frame line_det.

   lineloop:
   do with frame line_det:
      clear frame line_det all no-pause.
      view frame line_det.

      for first absl_det
         fields(absl_abs_id absl_abs_shipfrom absl_order absl_ord_line
                absl_lc_line absl_trl_code absl_lc_amt absl_charge_type
                absl_ref)
         no-lock
         where
            absl_abs_id = abs_id
         and absl_abs_shipfrom = abs_shipfrom
         and absl_order    = sod_nbr
         and absl_ord_line = sod_line:
      end.
      ctr = 0.
      do while ctr < frame-down and available absl_det:
         addcharge = code_desc(absl_trl_code).

         display
            absl_lc_line
            addcharge
            absl_trl_code
            absl_lc_amt
            absl_charge_type
            absl_ref.

         ctr = ctr + 1.
         if ctr < frame-down then down 1.

         find next absl_det no-lock
            where
               absl_abs_id = abs_id
            and absl_abs_shipfrom = abs_shipfrom
            and absl_order    = sod_nbr
            and absl_ord_line = sod_line
         no-error.
      end. /*DO WHILE CTR <*/

      up frame-line - 1.

      for first absl_det
         fields(absl_abs_id absl_abs_shipfrom absl_order absl_ord_line
                absl_lc_line absl_trl_code absl_lc_amt absl_charge_type
                absl_ref)
         no-lock
         where
            absl_abs_id = abs_id
         and absl_abs_shipfrom = abs_shipfrom
         and  absl_order    = sod_nbr
         and absl_ord_line = sod_line:
      end.

      priceloop:
      repeat with frame line_det:
/*GUI*/ if global-beam-me-up then undo, leave.

         ststatus = stline[1].
         status input ststatus.

         pause before-hide.
         prompt-for absl_lc_line
         go-on(F9 F10 CURSOR-UP CURSOR-DOWN).
         pause 0.

         if frame-field = "absl_lc_line" then
            next-prompt absl_lc_line.

         do while
            lastkey = keycode("F9")
            or lastkey = keycode("CURSOR-UP")
            or lastkey = keycode("F10")
            or lastkey = keycode("CURSOR-DOWN")
            on endkey undo, leave priceloop:

            if available absl_det then do:
               if lastkey = keycode("F9")
                  or lastkey = keycode("CURSOR-UP")
                  then do:

                  find prev absl_det where
                     absl_abs_id = abs_id
                     and absl_abs_shipfrom = abs_shipfrom
                     and absl_order = sod_nbr  and
                     absl_ord_line = sod_line
                  exclusive-lock no-error.

                  if available absl_det then do:
                     up 1.
                     addcharge = code_desc(absl_trl_code).

                     display
                        absl_lc_line
                        addcharge
                        absl_trl_code
                        absl_lc_amt
                        absl_charge_type
                        absl_ref.
                  end. /* IF AVAILABLE absl_det */
                  else do:
                     for first absl_det exclusive-lock where
                        absl_abs_id = abs_id
                        and absl_abs_shipfrom = abs_shipfrom
                        and absl_order = sod_nbr  and
                        absl_ord_line = sod_line:
                     end.
                  end. /* ELSE DO */
               end. /* if F9 or CURSOR-UP */

               else
                  if lastkey = keycode("F10")
                     or lastkey = keycode("CURSOR-DOWN")
                     then do:

                     find next absl_det where
                        absl_abs_id = abs_id
                        and absl_abs_shipfrom = abs_shipfrom
                        and absl_order = sod_nbr   and
                        absl_ord_line = sod_line
                     exclusive-lock no-error.

                     if available absl_det then do:
                        down 1.
                        addcharge = code_desc(absl_trl_code).

                        display
                           absl_lc_line
                           addcharge
                           absl_trl_code
                           absl_lc_amt
                           absl_charge_type
                           absl_ref.
                     end. /* IF AVAILABLE absl_det */
                     else do:
                        for last absl_det where
                           absl_abs_id = abs_id
                           and absl_abs_shipfrom = abs_shipfrom
                           and absl_order = sod_nbr  and
                           absl_ord_line = sod_line
                           exclusive-lock:
                        end.
                     end. /* ELSE DO */
               end. /* if F10 or CURSOR-DOWN */
            end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* if available absl_det */

            pause before-hide.
            prompt-for absl_lc_line
               go-on(F9 F10 CURSOR-UP CURSOR-DOWN).
            pause 0.

            if frame-field = "absl_lc_line" then
                            next-prompt absl_lc_line.
         end. /* do while lastkey F9 */

         for first absl_det where
            absl_abs_id = abs_id
            and absl_abs_shipfrom = abs_shipfrom
            and absl_order     = sod_nbr
            and absl_ord_line  = sod_line
            and absl_lc_line   = input absl_lc_line
            exclusive-lock:
         end.

         if input absl_lc_line < 1 or
            input absl_lc_line = "" then
            next priceloop.

         if not available absl_det then do:
            /*GET THE NEXT AVAILABLE LINE CHARGE */
            /* NUMBER AVAILABLE FOR ORDER LINE*/

            run get_next_line_nbr in THIS-PROCEDURE
               (INPUT (input absl_lc_line),
                INPUT sod_nbr,
                INPUT sod_line,
                OUTPUT new_line_nbr).

            /* WE CAN'T HAVE MORE THAN 999 RECORDS */
            /* FOR ANY GIVEN SALES ORDER LINE IN SODLC_DET */
            if new_line_nbr > 999 then
               next priceloop.

            new_absl_det = yes.

            /* ADDING NEW RECORD */
            {pxmsg.i &MSGNUM=1 &ERRORLEVEL=1}
            create absl_det.
            assign
               absl_order        = sod_nbr
               absl_ord_line     = sod_line
               absl_lc_line      = new_line_nbr
               absl_charge_type  = default_lc_type
               absl_abs_id       = abs_id
               absl_abs_shipfrom = abs_shipfrom
               absl_mod_userid   = global_userid
               absl_mod_date     = today.

            if recid(absl_det) = -1 then .

            /* IF NOT A SCHEDULED ORDER THEN WE NEED TO */
            /* CREATE DETAIL LINE CHARGE RECORDS FOR THE */
            /* TAX DETAILS*/

            create sodlc_det.
            assign
               sodlc_order         = sod_nbr
               sodlc_ord_line      = sod_line
               sodlc_lc_line       = new_line_nbr
               sodlc_charge_type   = default_lc_type
               sodlc_owned_by      = abs_id
               sodlc_abs_shipfrom  = abs_shipfrom
               sodlc_one_time      = no
               sodlc_times_charged = 1
               sodlc_mod_userid    = global_userid
               sodlc_mod_date      = today.

            if recid(sodlc_det) = -1 then .

         end. /* NOT AVAILABLE ABSL_DET */

         else new_absl_det = no.

         assign
            absldet_recid = recid(absl_det)
            where_we_are = frame-line.

         /* SET RECORD POINTER BEFORE ITERATIVELY FINDING PREV RECORD. */
         for first absl_det
            where recid(absl_det) = absldet_recid
            exclusive-lock:
         end.

         if new_absl_det and frame-line <> frame-down
            then do:
            do ctr = 1 to frame-down - 1  while available absl_det:
               find prev absl_det
                  where
                  absl_abs_id = abs_id
                  and absl_abs_shipfrom = abs_shipfrom
                  and absl_order = sod_nbr
                  and absl_ord_line = sod_line
               no-lock no-error.
            end. /* DO I = 1 TO FRAME-DOWN - 1 */

            if available absl_det
               then do:
               find prev absl_det
                  where
                  absl_abs_id = abs_id
                  and absl_abs_shipfrom = abs_shipfrom
                  and absl_order    = sod_nbr
                  and absl_ord_line = sod_line
               no-lock no-error.
            end. /* IF AVAIL absl_DET  */
         end. /* IF NEW_absl_DET AND.. */

         else
            do ctr = 1 to where_we_are while available absl_det:
               find prev absl_det where
                  absl_abs_id = abs_id
                  and absl_abs_shipfrom = abs_shipfrom
                  and absl_order = sod_nbr
                  and absl_ord_line = sod_line
               no-lock no-error.
         end.

         /* DETERMINE IF THE TOP MOST RECORD IN THE FRAME IS VERY FIRST */
         /* absl_det RECORD */
         if not available absl_det
            then
               l_is_first = yes.
         else
            l_is_first = no.

         up where_we_are - 1.

         do ctr = 1 to frame-down:
            if ctr = 1 and l_is_first
               then
                  for first absl_det
                     fields(absl_abs_id absl_abs_shipfrom absl_order
                            absl_ord_line absl_lc_line absl_trl_code
                            absl_lc_amt absl_charge_type absl_ref)
                     where
                     absl_abs_id = abs_id
                     and absl_abs_shipfrom = abs_shipfrom
                     and absl_order  = sod_nbr
                     and absl_ord_line = sod_line
                     no-lock:
                  end.
            else
               find next absl_det where
                  absl_abs_id = abs_id
                  and absl_abs_shipfrom = abs_shipfrom
                  and absl_order = sod_nbr
                  and absl_ord_line = sod_line
            no-lock no-error.

            if available absl_det then do:
               addcharge = code_desc(absl_trl_code).

               display
                  absl_lc_line
                  addcharge
                  absl_trl_code
                  absl_lc_amt
                  absl_charge_type
                  absl_ref.

               if recid(absl_det) = absldet_recid then do:
                  where_we_are = frame-line.
               end.
            end.
            else do:
               display
                  "" @ absl_lc_line
                  "" @ addcharge
                  "" @ absl_trl_code
                  "" @ absl_lc_amt
                  "" @ absl_charge_type
                  "" @ absl_ref.
            end.

            if ctr < frame-down then down 1.

         end. /* do ctr = 1 to frame-down */

         up frame-down - where_we_are.

         for first absl_det
            where
               recid(absl_det) = absldet_recid
            exclusive-lock:
         end.

         absldet_recid = recid(absl_det).
         ststatus = stline[2].
         status input ststatus.
         absl_updateable = no.
         sodlc_recno = ?.

         for first sodlc_det no-lock
            where
            sodlc_order = absl_order
            and sodlc_ord_line = absl_ord_line
            and sodlc_lc_line = absl_lc_line:

            sodlc_recno = recid(sodlc_det).

            if sodlc_owned_by = absl_abs_id and
               sodlc_abs_shipfrom = absl_abs_shipfrom
               then absl_updateable = yes.
         end.

         codeloop:
         do on error undo, retry:
/*GUI*/ if global-beam-me-up then undo, leave.

            pause before-hide.

            update
               absl_trl_code when (absl_updateable)
               absl_lc_amt when (absl_updateable)
               absl_charge_type when (absl_updateable)
               absl_ref
               go-on(F5 CTRL-D )
               with frame line_det editblk: editing:

               if frame-field = "absl_trl_code"
                  then do:
                  {mfnp05.i trl_mstr
                            trl_code
                            true
                            trl_code
                            absl_trl_code
                            ststatus}
                  if recno <> ? then do:
                     display
                        trl_code @ absl_trl_code
                        trl_desc @ addcharge
                        with frame line_det.
                  end.
               end.
               else if
                  frame-field = "absl_charge_type"
                     then do:
                     {mfnp09.i cct_mstr
                               absl_charge_type
                               cct_charge_type
                               cct_container_type
                               false
                               cct_charge_type}
                     if recno <> ? then do:
                        display
                           cct_charge_type @ absl_charge_type
                           with frame line_det.
                     end.
               end. /*ELSE IF*/
               else do:
                  readkey.
                  apply lastkey.
               end.

               if go-pending then do:
                  if input absl_trl_code = ""
                     then do:
                     /* BLANK NOT ALLOWED*/
                     {pxmsg.i &MSGNUM=40 &ERRORLEVEL=3}
                     next-prompt absl_trl_code with frame line_det.
                     next editblk.
                  end.

                  if not can-find(first trl_mstr where
                     trl_code = input absl_trl_code)
                     then do:
                     /*TRAILER CODE NOT DEFINED*/
                     {pxmsg.i &MSGNUM=4446 &ERRORLEVEL=3}
                     next-prompt absl_trl_code with frame line_det.
                     next editblk.
                  end.
                  if can-find(first absl_det where
                     absl_order = sod_nbr
                     and absl_ord_line = sod_line
                     and absl_trl_code = input absl_trl_code
                     and absl_lc_line <> input absl_lc_line)
                     then do:
                     /*CODE ALREADY USED...*/
                     {pxmsg.i &MSGNUM=4448 &ERRORLEVEL=3}
                     next-prompt absl_trl_code.
                     next editblk.
                  end. /* IF CAN-FIND(absl_DET...*/

                  if input absl_charge_type <> "" and
                     not can-find(first cct_mstr where
                     cct_charge_type = input absl_charge_type
                     and cct_container_type = no)
                     then do:
                     {pxmsg.i &MSGNUM=4396 &ERRORLEVEL=3}
                     /*NOT A VALID CHARGE TYPE*/
                     next-prompt absl_charge_type with frame line_det.
                     next editblk.
                  end.
               end. /*if go-pending*/
            end. /*editing*/
         end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /*codeloop*/
         if lastkey = keycode("F5")
            or lastkey = keycode("CTRL-D") then do:
            del-yn = yes.
            {pxmsg.i &MSGNUM=11 &ERRORLEVEL=1 &CONFIRM=del-yn}
             /* PLEASE CONFIRM DELETE */
            if del-yn = no then do:
               addcharge = code_desc(absl_trl_code).

               display
                  absl_lc_line
                  addcharge
                  absl_trl_code
                  absl_lc_amt
                  absl_charge_type
                  absl_ref.

               next priceloop.
            end.

            for first absl_det where
               absl_abs_id = abs_id
               and absl_abs_shipfrom = abs_shipfrom
               and absl_order = sod_nbr
               and absl_ord_line = sod_line
               and absl_lc_line = input absl_lc_line
               exclusive-lock:
            end.

            /* IF THE absl_det RECORD IS DELETED AND THE CHARGE */
            /* ORIGINALLY CAME FROM THE SALES ORDER, THEN WE    */
            /* NEED TO DECREMENT THE TIMES CHARGED FOR THAT     */
            /* SALES ORDER LINE CHARGE.                         */

            if available absl_det then do:
               for first sodlc_det exclusive-lock where
                  sodlc_order = absl_order  and
                  sodlc_ord_line = absl_ord_line  and
                  sodlc_lc_line = absl_lc_line:

                  if sodlc_owned = absl_abs_id
                     and sodlc_abs_shipfrom = absl_abs_shipfrom
                     then
                        delete sodlc_det.
                  else do:
                     /* IF THE RECORD WAS NOT CREATED BY THIS SHIPPER*/
                     /* THEN DO NOT ALLOW THE DELETETION*/
                     {pxmsg.i &MSGNUM=1021 &ERRORLEVEL=3}
                     /*DELETE NOT ALLOWED*/
                     next priceloop.
                  end.
               end. /* FOR FIRST sodlc_det */
            end. /* IF AVAILABLE absl_det */

            delete absl_det.

            where_we_are = frame-line.

            find next absl_det where
               absl_abs_id = abs_id
               and absl_abs_shipfrom = abs_shipfrom
               and absl_order = sod_nbr
               and absl_ord_line = sod_line
            no-lock no-error.

            if available absl_det then do:
               absldet_recid = recid(absl_det).

               addcharge = code_desc(absl_trl_code).

               display
                  absl_lc_line
                  addcharge
                  absl_trl_code
                  absl_lc_amt
                  absl_charge_type
                  absl_ref.

               do ctr = where_we_are to frame-down - 1:
                  down 1.
                  find next absl_det where
                     absl_abs_id = abs_id
                     and absl_abs_shipfrom = abs_shipfrom
                     and absl_order = sod_nbr
                     and absl_ord_line = sod_line
                  no-lock no-error.
                  if available absl_det then do:
                     addcharge = code_desc(absl_trl_code).

                     display
                        absl_lc_line
                        addcharge
                        absl_trl_code
                        absl_lc_amt
                        absl_charge_type
                        absl_ref.
                  end.

                  else do:
                     display
                        "" @ absl_lc_line
                        "" @ addcharge
                        "" @ absl_trl_code
                        "" @ absl_lc_amt
                        "" @ absl_charge_type
                        "" @ absl_ref.
                  end.
               end. /* do ctr = where_we_are */

               up frame-down - where_we_are.
               for first absl_det
                  where
                  recid(absl_det) = absldet_recid
                  exclusive-lock:
               end.
            end. /* if available absl_det */

            else do:
               display
                  "" @ absl_lc_line
                  "" @ addcharge
                  "" @ absl_trl_code
                  "" @ absl_lc_amt
                  "" @ absl_charge_type
                  "" @ absl_ref.

               find prev absl_det where
                  absl_abs_id = abs_id
                  and absl_abs_shipfrom = abs_shipfrom
                  and absl_order = sod_nbr
                  and absl_ord_line = sod_line
               exclusive-lock no-error.

               if available absl_det then do:
                  up 1.
                  addcharge = code_desc(absl_trl_code).

                  display
                     absl_lc_line
                     addcharge
                     absl_trl_code
                     absl_lc_amt
                     absl_charge_type
                     absl_ref.
               end.
            end.
         end. /* if lastkey = F5 */

         else
            if keyfunction(lastkey) = "END-ERROR":U
               then do:
               addcharge = code_desc(absl_trl_code).

               display
                  addcharge
                  absl_trl_code
                  absl_lc_amt
                  absl_charge_type
                  absl_ref.
         end.

         else do:
            vQty = (if abs_ship_qty <> 0 then abs_ship_qty else abs_qty).
            assign
               line_price = if vQty < 0 then
                           (input absl_lc_amt * -1) else input absl_lc_amt
               absl_trl_code = input absl_trl_code
               absl_charge_type = input absl_charge_type
               absl_ref = input absl_ref.

            {pxrun.i &PROC  = 'getLineChargeAccounts'
                     &PROGRAM = 'cclcxr.p'
                     &HANDLE = ph_cclcxr
                     &PARAM = "(input absl_trl_code,
                                output vSalesAccount,
                                output vSubAccount,
                                output vCostcenter,
                                output vTaxable,
                                output vTaxClass)"}


              {pxrun.i &PROC  = 'updateChargeTypePrice'
                       &PROGRAM = 'cclcxr.p'
                       &HANDLE = ph_cclcxr
                       &PARAM = "(input absl_charge_type,
                                  input no,
                                  input-output line_price,
                                  input ipSoRecNo,
                                  input ipSodRecNo,
                                  input sodlc_recno,
                                  input recid(abs_mstr),
                                  input recid(absl_det),
                                  output op_price)"}

            assign
               absl_acct = vSalesAccount
               absl_sub = vSubAccount
               absl_cc = vCostCenter
               absl_taxable = vTaxable
               absl_taxc = vTaxClass
               absl_ext_price = op_price
               absl_lc_amt = if vQty < 0 then (line_price * -1)
                             else line_price.

            display absl_lc_amt with frame line_det.

            for first sodlc_det exclusive-lock where
               sodlc_order = absl_order  and
               sodlc_ord_line = absl_ord_line  and
               sodlc_lc_line = absl_lc_line and
               sodlc_owned_by = absl_abs_id and
               sodlc_abs_shipfrom = absl_abs_shipfrom:

               assign
                  sodlc_trl_code = absl_trl_code
                  sodlc_lc_amt = absl_lc_amt
                  sodlc_charge_type = absl_charge_type
                  sodlc_ref = absl_ref
                  sodlc_acct = absl_acct
                  sodlc_cc = absl_cc
                  sodlc_taxable = absl_taxable
                  sodlc_taxc = absl_taxc
                  sodlc_sub = absl_sub
                  sodlc_ext_price = op_price.

            end. /*FOR FIRST SODLC_DET */

            if new_absl_det and frame-line <> frame-down then do:
               assign
                  absldet_recid = recid(absl_det)
                  where_we_are = frame-line.

               do ctr = 1 to where_we_are + 1 while available absl_det:
                  find prev absl_det where
                     absl_abs_id = abs_id
                     and absl_abs_shipfrom = abs_shipfrom
                     and absl_order = sod_nbr
                     and absl_ord_line = sod_line
                     no-lock no-error.
               end.

               up where_we_are - 1.

               /* DETERMINE IF THE TOP MOST RECORD IN THE FRAME */
               /* IS VERY FIRST absl_DET RECORD                */

               if not available absl_det
                  then
                  l_is_first = yes.
               else
                  l_is_first = no.

               do ctr = 1 to frame-down:
                  if ctr = 1 and l_is_first
                     then
                     for first absl_det
                        fields(absl_abs_id absl_abs_shipfrom absl_order
                               absl_ord_line absl_lc_line absl_trl_code
                               absl_lc_amt absl_charge_type absl_ref)
                        where
                        absl_abs_id = abs_id
                        and absl_abs_shipfrom = abs_shipfrom
                        and absl_order = sod_nbr
                        and absl_ord_line = sod_line
                        no-lock :
                  end. /* FOR FIRST absl_DET */

                  else
                     find next absl_det where
                        absl_abs_id = abs_id
                        and absl_abs_shipfrom = abs_shipfrom
                        and absl_order = sod_nbr
                        and absl_ord_line = sod_line
                  no-lock no-error.

                  if available absl_det then do:
                     addcharge = code_desc(absl_trl_code).
                     display
                        absl_lc_line
                        addcharge
                        absl_trl_code
                        absl_lc_amt
                        absl_charge_type
                        absl_ref.

                     if recid(absl_det) = absldet_recid then do:
                        where_we_are = frame-line.
                     end.
                  end.

                  else do:
                     display
                        "" @ absl_lc_line
                        "" @ addcharge
                        "" @ absl_trl_code
                        "" @ absl_lc_amt
                        "" @ absl_charge_type
                        "" @ absl_ref.
                  end.

                  if ctr < frame-down then down 1.
               end. /* do ctr = 1 to frame-down */

               up frame-down - where_we_are.
               for first absl_det
                  where
                  recid(absl_det) = absldet_recid
                  exclusive-lock:
               end.

               absldet_recid = recid(absl_det).
            end. /* if new_absl_det */
         end. /* else do */
      end. /*priceloop*/
   end. /*LINELOOP*/
end. /* IF default_edit_lc_shipper */

hide frame line_det no-pause.


PROCEDURE set_tax_date:
   define input parameter ip_so_nbr like so_nbr no-undo.
   define input parameter ip_tax_date like so_tax_date no-undo.

   define buffer b_so_mstr for so_mstr.

   for first b_so_mstr where b_so_mstr.so_nbr = ip_so_nbr:
      if b_so_mstr.so_tax_date = ? then
         b_so_mstr.so_tax_date = ip_tax_date.
   end.

END PROCEDURE.


PROCEDURE get_next_line_nbr:
   define input parameter ip_line like absl_lc_line no-undo.
   define input parameter ip_order like sod_nbr no-undo.
   define input parameter ip_order_line like sod_line no-undo.
   define output parameter op_new_line_nbr like absl_lc_line no-undo.

   define buffer bf_sodlc_det for sodlc_det.

   define variable next_line_nbr like absl_lc_line no-undo.

   for first bf_sodlc_det no-lock
       where
           bf_sodlc_det.sodlc_order = ip_order
       and bf_sodlc_det.sodlc_ord_line = ip_order_line
       and bf_sodlc_det.sodlc_lc_line = ip_line:
   end.

   if available bf_sodlc_det then do:
       next_line_nbr = ip_line + 1.
       run get_next_line_nbr in THIS-PROCEDURE
          (INPUT next_line_nbr,
           INPUT ip_order,
           INPUT ip_order_line,
           OUTPUT op_new_line_nbr).

   end.

   else op_new_line_nbr = ip_line.

END PROCEDURE.

PROCEDURE charge_label:
   define input parameter chargecode like trl_code no-undo.
   define output parameter chargedesc like trl_desc no-undo.

   for first trl_mstr
      fields (trl_code trl_desc)
      where
       trl_code = chargecode
       no-lock:
       chargedesc = trl_desc.
   end.

END PROCEDURE.
